package com.jar.exercise.集合和数据结构.队列.数组实现队列.顺序队列;

public class Main {

}
class MyQueue{
    private String[] values;
    private int capacity; 
    private int head = -1;
    private int tail = -1;

    public MyQueue(int capacity) {
        this.capacity = capacity;
        values = new String[capacity];
    }

    private boolean enqueue(String value) {
        if (tail == capacity-1) {
            return false;
        }
        values[++tail] = value;
        return true;
    }

    private String dequeue() {
        if (head == tail) {
            return "没有东西了";
        }
        String value = values[++head];
        values[head] = null;
        return value;
    }
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue(3);
        System.out.println(myQueue.enqueue("z"));
        System.out.println(myQueue.enqueue("2"));
        System.out.println(myQueue.enqueue("1"));
        System.out.println(myQueue.enqueue("4"));

        System.out.println(myQueue.dequeue());
        System.out.println(myQueue.enqueue("4"));
        System.out.println(myQueue.dequeue());
        System.out.println(myQueue.dequeue());
        System.out.println(myQueue.dequeue());
        System.out.println(myQueue.dequeue());

    }
}
